package com.blue.starter.advice;

import com.blue.common.exception.BizIllegalException;
import com.blue.starter.core.AjaxResult;
import com.blue.common.exception.UnauthorizedException;
import com.blue.starter.core.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author : CaiYang
 * @Date : 2025-03-20 15:26
 * @Description :
 */
@RestControllerAdvice
@Slf4j
public class CommonExceptionAdvice {

    /**
     * 全局异常处理，没有值定异常的类型，不管是什么异常都可以捕获
     * @param e
     * @return
     */
    @ExceptionHandler(UnknownError.class)
    @ResponseBody
    public AjaxResult error(UnauthorizedException e){
        e.printStackTrace();
        return new AjaxResult(e.getMessage(),"401");
    }

    @ExceptionHandler(BizIllegalException.class)
    @ResponseBody
    public AjaxResult error(BizIllegalException e){
        e.printStackTrace();
        return new AjaxResult(e.getMessage(),"500");
    }
}
